/*
 * Copyright (c) 2024. Shanghai HEADING information Engineering Co., Ltd. All rights reserved.
 */
package com.lovely602.design.study.basic;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author lizhixing
 */
public class URLTest {


  public static void main(String[] args) throws IOException {

    String urlStr = "https://essp.oss-cn-hangzhou.aliyuncs.com/mas/ie8bez4n7zfaySDF.png";

    URL url = new URL(urlStr);
    URLConnection urlConnection = url.openConnection();
    urlConnection.connect();
    InputStream is = urlConnection.getInputStream();

    FileOutputStream fos = new FileOutputStream("D:\\test.png");
    byte[] bytes = new byte[1024];
    while (is.read(bytes) != -1) {
      fos.write(bytes);
    }
    fos.close();
    is.close();
  }
}
